//引入mongoose
const mongoose = require('mongoose');
//链接数据库
mongoose.connect('mongodb://127.0.0.1:27017/book-crud');

//向外暴露绑定监视函数
// 让调用者传入连接成功和失败的回调
module.exports = (onSuccess, onError) => {
    //绑定链接成功的回调
    mongoose.connection.on('open', onSuccess);
    //绑定链接失败的回调
    mongoose.connection.on('error', onError);
}

